project(PANDA_APP_NATIVE)

add_library(calc_lib SHARED calc_impl.cpp)
target_include_directories(calc_lib PRIVATE "${ANI_INCLUDE_DIR}")
target_include_directories(calc_lib PRIVATE ${PANDA_HELPERS_SOURCE_DIR})

set(ARKTSCONFIG_PATH "${CMAKE_CURRENT_BINARY_DIR}/arktsconfig.json")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/arktsconfig.json.in" "${ARKTSCONFIG_PATH}")

compile_panda_source(
    SRC_FILE_NAME "main.ets"
    ARKTSCONFIG "${ARKTSCONFIG_PATH}"
    TARGET_NAME panda_app_native_abc
)

ark_aot(
    TARGET_NAME
        panda_app_native_aot
    ABC_FILE
        "main.abc"
    EXTRA_BOOT_PANDA_FILES
        ${MEASURE_NATIVE_LIB_BINARY_DIR}/MeasureNativeLib.abc
        ${TST_LIB_BINARY_DIR}/TstLib.abc
    EXTRA_DEPS
        panda_app_native_abc
        measure_native_lib_abc
        tst_lib_abc
)

run_panda_abc(
    TARGET_NAME panda_app_native
    ABC_FILE_NAME "main.abc"
    EXTRA_BOOT_PANDA_FILES
        ${MEASURE_NATIVE_LIB_BINARY_DIR}/MeasureNativeLib.abc
        ${TST_LIB_BINARY_DIR}/TstLib.abc
    ADDITIONAL_OPTIONS
        "--log-components=AOT"
        "--log-level=debug"
        "--native-library-path=${PANDA_APP_NATIVE_BINARY_DIR}:${MEASURE_NATIVE_LIB_BINARY_DIR}:${TST_LIB_BINARY_DIR}"
        "--aot-files=${MEASURE_NATIVE_LIB_BINARY_DIR}/MeasureNativeLib.an:${TST_LIB_BINARY_DIR}/TstLib.an:${CMAKE_CURRENT_BINARY_DIR}/main.an"
        ##"--sampling-profiler-create=true"
        "--compiler-enable-jit=false"
        "--workers-type=threadpool"
        #"--verification-mode=disabled"
        #"--verification-mode=ahead-of-time"
        #"--interpreter-type=cpp"
        #"--log-components=AOT:classlinker:runtime:interpreter"
        #"--log-components=classlinker"
        #"--log-level=debug"
    EXTRA_DEPS
        calc_lib
        measure_native_lib_srcs
        tst_lib_srcs
        panda_app_native_abc
        panda_app_native_aot
)
